﻿using System;
using System.Data.Entity;
using System.Linq;
using IceDog.DNF.Program.Ef6.Models;

namespace IceDog.DNF.Program.Ef6.EfContext
{
    /// <summary>
    ///  Order数据库总是删除重新新建
    /// </summary>
    public class OrderInitializerForDropCreateDatabaseAlways:DropCreateDatabaseAlways<OrderContext>
    {
        /// <summary>
        /// A method that should be overridden to actually add data to the context for seeding.
        /// The default implementation does nothing.
        /// </summary>
        /// <param name="context"> The context to seed. </param>
        protected override void Seed(OrderContext context)
        {
            var orders = Enumerable.Range(1, 20).Select(i => new Order()
            {
                Customer = $"customer{i}",
                OrderDate = DateTime.Now
            });
            context.Orders.AddRange(orders);
            context.SaveChanges();
        }
    }
}
